package com.itheima.loop;

public class ForDemo3 {
    public static void main(String[] args) {
        // 目标：求1-10所有奇数的和。
            int sum = 0;
        for (int i = 0; i <= 10 ; i++) {
            if(i % 2 == 1){
                sum += i;
            }
        }
        System.out.println("所有奇数的和为：" + sum);

        System.out.println("----------方法2----------");

        int sum2 = 0;
        for (int j = 1; j <= 10; j+=2) {
            sum2 += j;
        }
        System.out.println("所有奇数的和为：" + sum2);
    }
}
